<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath }/css/css.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery-1.8.2.js" ></script>
<title>Insert title here</title>
</head>
<body>
	<form action="add" method="post">
	学生
	<select name="uid" onchange="change3()">
	<option value="">请选择</option>
	<c:forEach items="${user }" var="u">
	<option value="${u.uid }">${u.uname }</option>
	</c:forEach>
	</select><br><br>
	
	宿舍楼
	<select name="fid" onchange="change()">
	<option value="">请选择</option>
	</select><br><br>
	宿舍号
	<select name="did" onchange="change2()">
	<option value="">请选择</option>
	</select><br><br>
	当前宿舍人数
	<span id="s1" ></span><br><br>
	
	当前宿舍入住人名
	<span id="s2" ></span><br><br>
	
	<span id="s3" >
	<input type="button" value="入住" disabled="disabled"  > 
	</span>
	
	</form>
<script type="text/javascript">

function change3(){
	if($("[name='uid']").val()!=null && $("[name='uid']").val()!="" ){
		alert("入住可用")
		$("#s3").html("<input type='submit' value='入住' >")
	}
}





$.post(
	"liandongF",
	{},
	function(msg){
		for (var i = 0; i < msg.length; i++) {
			$("[name='fid']").append("<option value='"+msg[i].fid+"'>"+msg[i].fname+"</option>")
		}
	},
	"json"
			
)
function change(){
	var fid=$("[name='fid']").val();
	$("[name='did']").html("<option value=''>请选择</option>")
	$.post(
			"liandongD",
			{fid:fid},
			function(msg){
				for (var i = 0; i < msg.length; i++) {
					$("[name='did']").append("<option value='"+msg[i].did+"'>"+msg[i].dname+"</option>")
				}
				
			},
			"json"
					
		)
	
}
function change2(){
	
	var did=$("[name='did']").val();P
	$.post(
		"selectR2",
		{did:did},
		function(msg){
			$("#s1").html(" <input type='text' value='"+msg.count+"' readonly='readonly'> ");
			$("#s2").html(" <input type='text' value='"+msg.uname+"' readonly='readonly'> ");
		},
		"json"
	)
}

</script>
</body>
</html>